/*
 * 程序清单：这是一个 CAN 设备使用例程
 * 例程导出了 can_sample 命令到控制终端
 * 命令调用格式：can_sample can1
 * 命令解释：命令第二个参数是要使用的 CAN 设备名称，为空则使用默认的 CAN 设备
 * 程序功能：通过 CAN 设备发送一帧，并创建一个线程接收数据然后打印输出。
*/

#include <rtthread.h>
#include "rtdevice.h"
#include <board.h>

#ifndef ULOG_USING_SYSLOG
#define LOG_TAG              "gpio.test"
#define LOG_LVL              LOG_LVL_DBG
#include <ulog.h>
#else
#include <syslog.h>
#endif /* ULOG_USING_SYSLOG */


/* defined the gpio_test pin: C10 */
#define GPIO1_PIN               GET_PIN(B, 10)
#define GPIO2_PIN               GET_PIN(E, 15)
#define GPIO3_PIN               GET_PIN(E, 14)
#define GPIO4_PIN               GET_PIN(E, 13)
#define GPIO5_PIN               GET_PIN(E, 12)
#define GPIO6_PIN               GET_PIN(E, 11)
#define GPIO7_PIN               GET_PIN(C, 4)
#define GPIO8_PIN               GET_PIN(C, 5)

#define GPIO9_PIN               GET_PIN(E, 4)
#define GPIO10_PIN               GET_PIN(E, 5)

#define GPIO11_PIN               GET_PIN(E, 6)

#define GPIO12_PIN               GET_PIN(B, 12)
#define GPIO13_PIN               GET_PIN(B, 13)
#define GPIO14_PIN               GET_PIN(B, 14)

#define GPIO15_PIN               GET_PIN(B, 3)
#define GPIO16_PIN               GET_PIN(B, 4)



int gpio_test(void)
{
    int count = 1;
    /* set GPIO0 pin mode to output */
    rt_pin_mode(GPIO1_PIN, PIN_MODE_OUTPUT);
    rt_pin_mode(GPIO2_PIN, PIN_MODE_OUTPUT);
    rt_pin_mode(GPIO3_PIN, PIN_MODE_OUTPUT);
    rt_pin_mode(GPIO4_PIN, PIN_MODE_OUTPUT);
    rt_pin_mode(GPIO5_PIN, PIN_MODE_OUTPUT);
    rt_pin_mode(GPIO6_PIN, PIN_MODE_OUTPUT);
    rt_pin_mode(GPIO7_PIN, PIN_MODE_OUTPUT);
    rt_pin_mode(GPIO8_PIN, PIN_MODE_OUTPUT);

    rt_pin_mode(GPIO9_PIN, PIN_MODE_OUTPUT);
    rt_pin_mode(GPIO10_PIN, PIN_MODE_OUTPUT);
    rt_pin_mode(GPIO11_PIN, PIN_MODE_OUTPUT);
    rt_pin_mode(GPIO12_PIN, PIN_MODE_OUTPUT);
    rt_pin_mode(GPIO13_PIN, PIN_MODE_OUTPUT);
    rt_pin_mode(GPIO14_PIN, PIN_MODE_OUTPUT);
    rt_pin_mode(GPIO15_PIN, PIN_MODE_OUTPUT);
    rt_pin_mode(GPIO16_PIN, PIN_MODE_OUTPUT);

    while (count++)
    {
        rt_pin_write(GPIO1_PIN, PIN_LOW);
        rt_pin_write(GPIO2_PIN, PIN_LOW);
        rt_pin_write(GPIO3_PIN, PIN_LOW);
        rt_pin_write(GPIO4_PIN, PIN_LOW);
        rt_pin_write(GPIO5_PIN, PIN_LOW);
        rt_pin_write(GPIO6_PIN, PIN_LOW);
        rt_pin_write(GPIO7_PIN, PIN_LOW);
        rt_pin_write(GPIO8_PIN, PIN_LOW);

        rt_pin_write(GPIO9_PIN, PIN_LOW);
        rt_pin_write(GPIO10_PIN, PIN_LOW);
        rt_pin_write(GPIO11_PIN, PIN_LOW);
        rt_pin_write(GPIO12_PIN, PIN_LOW);
        rt_pin_write(GPIO13_PIN, PIN_LOW);
        rt_pin_write(GPIO14_PIN, PIN_LOW);
        rt_pin_write(GPIO15_PIN, PIN_LOW);
        rt_pin_write(GPIO16_PIN, PIN_LOW);
        rt_thread_mdelay(500);
        rt_pin_write(GPIO1_PIN, PIN_HIGH);
        rt_pin_write(GPIO2_PIN, PIN_HIGH);
        rt_pin_write(GPIO3_PIN, PIN_HIGH);
        rt_pin_write(GPIO4_PIN, PIN_HIGH);
        rt_pin_write(GPIO5_PIN, PIN_HIGH);
        rt_pin_write(GPIO6_PIN, PIN_HIGH);
        rt_pin_write(GPIO7_PIN, PIN_HIGH);
        rt_pin_write(GPIO8_PIN, PIN_HIGH);

        rt_pin_write(GPIO9_PIN, PIN_HIGH);
        rt_pin_write(GPIO10_PIN, PIN_HIGH);
        rt_pin_write(GPIO11_PIN, PIN_HIGH);
        rt_pin_write(GPIO12_PIN, PIN_HIGH);
        rt_pin_write(GPIO13_PIN, PIN_HIGH);
        rt_pin_write(GPIO14_PIN, PIN_HIGH);
        rt_pin_write(GPIO15_PIN, PIN_HIGH);
        rt_pin_write(GPIO16_PIN, PIN_HIGH);
        rt_thread_mdelay(500);

    }

    return RT_EOK;
}

/* 导出到 msh 命令列表中 */
MSH_CMD_EXPORT(gpio_test, gpio test sample);